var loca=location.href;
//查看所有可能认识的人
if(/showallrela/.test(loca)){
    $("title").html("可能认识");
    $("#friends").html("可能认识");
    //环信建立连接
    var conn = new WebIM.connection({
        https: WebIM.config.https,
        url: WebIM.config.xmppURL,
        isAutoLogin: WebIM.config.isAutoLogin,
        isMultiLoginSessions: WebIM.config.isMultiLoginSessions
    });
//登录
    var options = {
        apiUrl: WebIM.config.apiURL,
        user:id,
        pwd:id,
        appKey: "pulu#pulu"
    };
    conn.open(options);
    //添加好友
    function addfri(e){
        if(e.className==="straddbtn"){
            //发送好友模板
            $.ajax({
                type:"post",
                url:savefriendnoteurl0,
                data:{"userId": $.cookie("MYID"),"friendId":e.dataset.uid,"msg":""},
                success:function(d){

                }
            });
            e.className="straddbtn clicked";
            //e.innerHtml="已发送请求";
            conn.subscribe({
                to: e.dataset.uid,
                message: $.cookie("MYNICK")+"请求添加你为好友"
            });
        }
    }
    $.ajax({
        type:"get",
        url:"https://www.pulu.com/webapi/api/puluuser/GetMayKnowAllUsers?userid="+id,
        datatype:"json",
        success:function(data){
            console.log(data);
            var code="";
            for(var i=0;i<data.Data.length;i++){
                var userimg;//头像
                if(data.Data[i].userAva){
                    userimg="<img class='topic_photo_img' src='"+imgurl+data.Data[i].userAva+"'/>";
                }else{
                    userimg="<img class='topic_photo_img' src='img/af8.png'/>"
                }
                //
                var thisRealName="";
                if(data.Data[i].realName){thisRealName=" ("+data.Data[i].realName+")";}
                code+="<div class='Cell'> <div class='friends'> <div class='imageplace'> <a href='otherpeoplepage.html?otherid="+data.Data[i].userId+"'>"+userimg+"</a> </div> <div class='innerplace'> <div> <a href='otherpeoplepage.html?otherid="+data.Data[i].userId+"' class='tc_text'>"+data.Data[i].userNick+thisRealName+"</a><br><a href='relapeoplelist.html?otherid="+data.Data[i].userId+"'>"+data.Data[i].commonCount+"位共同好友</a></div></div><div class='straddbtn' data-uid='"+data.Data[i].userId+"' onclick='addfri(this)'>+加好友</div></div></div>"
            }
            $("#listplace ").append(code);
        },
        error:function(d){
            console.log(d);
        }
    });
    console.log("可能认识的好友");
}
else if(/otherid/.test(loca)){
    var otherid=loca.match(/otherid=[0-9a-z]+/)[0].split("=")[1];
    $.ajax({
        type:"get",
        url:"https://www.pulu.com/webapi/api/puluuser/GetCommonFriends?userid1="+id+"&userid2="+otherid,
        datatype:"json",
        success:function(data){
            var code="";
            for(var i=0;i<data.Data.length;i++){
                var userimg;//头像
                if(data.Data[i].commonUserAva){
                    userimg="<img class='topic_photo_img' src='"+imgurl+data.Data[i].commonUserAva+"'/>";
                }else{
                    userimg="<img class='topic_photo_img' src='img/af8.png'/>"
                }
                var realnick="";
                if(data.Data[i].realName){
                    realnick=" ("+data.Data[i].realName+")";
                }
                code+="<div class='Cell'> <div class='friends'> <div class='imageplace'> <a href='otherpeoplepage.html?otherid="+data.Data[i].commonUserId+"'>"+userimg+"</a> </div> <div class='innerplace'> <a href='otherpeoplepage.html?otherid="+data.Data[i].commonUserId+"'> <span class='tc_text'>"+data.Data[i].commonUserNick+realnick+"</span></a></div></div></div>";
            }
            $("#listplace ").append(code);
        }
    });
}